﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microhard.Core;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microhard.WarehouseInsp.Buz.Models;
using Microhard.WarehouseInsp.Buz.DataAccess;
using Microhard.Permission.MVCFilter;
using Telerik.Web.Mvc;
using Microhard.Permission.Models;

namespace Microhard.WarehouseInsp.WebUI.Areas.WarehouseInsp.Controllers
{
    public class PrjMonitorController : Controller
    {
        [MVCFilterAtrForLogon(Order = 0)]//登录验证
        [MVCFilterAtrForResourcePermission(Order = 1)]//功能权限验证
        public ActionResult Index()
        {
            ISupProject temp = IoC.Resolve<ISupProject>();
            List<SupProjectModel> list = temp.GetAllSupProject();
            return View(list);
        }

        [MVCFilterAtrForLogon(Order = 0)]//登录验证
        [MVCFilterAtrForResourcePermission(Order = 1, OperationKeyName = "Index")]//功能权限验证
        public ActionResult MainTab(SupProjectModel sup)
        {
            return View(sup);
        }

        [MVCFilterAtrForLogon]//登录验证
        [MVCFilterAtrForResourcePermission(Order = 1, OperationKeyName = "Index")]//功能权限验证
        public ActionResult GetPledgeChat(Guid PrjID)
        {
            ISuprjWarnDetail temp = IoC.Resolve<ISuprjWarnDetail>();
            ISupProject temp2 = IoC.Resolve<ISupProject>();
            SupervisionDetailModel sup = new SupervisionDetailModel();
            sup.ProjectID = PrjID;
            SupervisionDetailModel superList = temp.GetModelByModel(sup);

            List<PledgeChangeRecordModel> pledgeList = temp2.GetPledgeChangeRecords(PrjID);

            List<PledgeChatModel> list = new List<PledgeChatModel>();

            foreach (PledgeChangeRecordModel p in pledgeList)
            {

                PledgeChatModel pled = new PledgeChatModel();
                pled.DateString = p.CreateTime.ToString();

                pled.Guard = superList.Guardline;
                pled.Amount = p.CurrentAmount;
                pled.Warn = superList.WarnAmount;


                list.Add(pled);

            }


            return View(list);
        }

        public ActionResult GetSupervisionDetail(Guid PrjID)
        {

            SupProjectModel model = new SupProjectModel();
            model.ProjectID = PrjID;

            return View(model);
        }

        public ActionResult GetPrjBaseInfo(Guid prjID)
        {
            ISupProject temp = IoC.Resolve<ISupProject>();
            SupProjectModel model = temp.GetModelByID(prjID);
            //为字段中的字典显示字段赋值
            SetDictionaryFiledName.SetDicFiledTxtName<SupProjectModel>(ref model);
            return View(model);
        }

        public ActionResult GetOutPutRecords(Guid prjID)
        {
            SupProjectModel model = new SupProjectModel();
            model.ProjectID = prjID;
            return View(model);
        }

        public ActionResult _OutPutRecords(Guid prjID)
        {
            IOutIntPutWarehouse temp = IoC.Resolve<IOutIntPutWarehouse>();
            List<OutIntPutWarehouseModel> outIntPutList = temp.GetOutRecordByProject(prjID);

            var outModel = new GridModel()
            {
                Data = outIntPutList
            };
            return new JsonResult
            {
                Data = outModel,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet

            };

        }

        public ActionResult GetInPutRecords(Guid prjID)
        {
            SupProjectModel model = new SupProjectModel();
            model.ProjectID = prjID;
            return View(model);
        }

        public ActionResult _InPutRecords(Guid prjID)
        {
            IOutIntPutWarehouse temp = IoC.Resolve<IOutIntPutWarehouse>();
            List<OutIntPutWarehouseModel> IntPutList = temp.GetInRecordByProject(prjID);

            var inModel = new GridModel()
            {
                Data = IntPutList
            };
            return new JsonResult
            {
                Data = inModel,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet

            };

        }
        public ActionResult GetPledgePlanInRecords(Guid PrjID)
        {
            SupProjectModel model = new SupProjectModel();
            model.ProjectID = PrjID;
            return View(model);
        }

        public ActionResult GetRiskRecords(Guid PrjID)
        {
            SupProjectModel model = new SupProjectModel();
            model.ProjectID = PrjID;
            return View(model);
        }

    }
}
